package com.wc.AlgoOJ_train.train5_数据结构.c2_队列.DS0101_非标队列;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congege
 * @Description
 * @Date Created in 2024/2/3-11:04
 * http://43.138.190.70:8888/p/DS0101
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 100010;
    static int[] a = new int[N];
    static int peek = 1;
    static int tail = 1;
    static int n, x;

    public static void main(String[] args) {
        n = sc.nextInt();
        while (n-- > 0) {
            String operator = sc.next();
            if (operator.equals("push")) {
                x = sc.nextInt();
                a[tail++] = x;
            } else if (operator.equals("pop")) {
                x = a[peek];
                peek++;
//                out.println(x);
            } else {
                x = sc.nextInt();
                out.println(a[peek + x - 1]);
            }
        }
        out.flush();
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    boolean hasNext() {
        while (st == null || !st.hasMoreElements()) {
            String s = nextLine();
            if (s == null) {
                return false;
            }
            st = new StringTokenizer(s);
        }

        return true;
    }
}
